package com.e.dianshang.controller;

import com.e.dianshang.pojo.Brand;
import com.e.dianshang.service.BrandService;
import com.e.dianshang.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Description: TOOD
 * @ClassName: TicketController
 * @Author: ${陈柯宇}
 * Date: 2020/11/10 10:22
 * @Version: 1.0
 */
@RestController
@Api(value = "商品详情筛选接口",tags = "品牌、条件搜索商品")
public class BrandController {

    @Resource
    BrandService brandService;

    /**
     * 搜索所有商品品牌
     * @return
     */
    @PostMapping(value = "/findAllBrand",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "搜索所有商品品牌的接口")
    public Map findAllBrand() {
        JsonResult jsonResult=new JsonResult();
        List<Brand> allBrand = brandService.findAllBrand();
        jsonResult.setCode("200");
        jsonResult.setMsg("检索成功");
        jsonResult.setData(allBrand);
        return jsonResult.getValues();
    }


    /**
     * 根据品牌查找对应的规格
     * @param id 品牌id
     * @return
     */
    @ApiOperation(value = "根据品牌查找对应的规格的接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "品牌id",required = true, dataType = "Integer",paramType = "query")})
    @RequestMapping(value = "/findGoodsByBrand",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map findGoodsByBrand(@RequestParam("id")int id){
        JsonResult jsonResult=new JsonResult();
        List<Map<String, Object>> goodsByBrand = brandService.findGoodsByBrand(id);
        jsonResult.setCode("200");
        jsonResult.setMsg("检索成功");
        jsonResult.setData(goodsByBrand);
        return jsonResult.getValues();
    }

    /**
     * 根据品牌及对应的规格找商品
     * @param id, memory, color, size
     * @return
     */
    @ApiOperation(value = "根据品牌及对应的规格找商品的接口")
    @ApiImplicitParams({@ApiImplicitParam(name = "id",value = "品牌id",required = true, dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name = "memory",value = "内存",required = false, dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "color",value = "颜色",required = false, dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "尺寸",required = false, dataType = "String",paramType = "query")})
    @RequestMapping(value = "/findGoodsAllByBrand",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    //@RequestParam("id")Integer id,@RequestParam(value = "memory",required = false)String memory,@RequestParam(value = "color",required = false)String color,@RequestParam(value = "size",required = false)String size
    public Map findGoodsAllByBrand(@RequestParam("id")int id,@RequestParam(value = "memory",required = false)String memory,@RequestParam(value = "color",required = false)String color,@RequestParam(value = "size",required = false)String size){
        JsonResult jsonResult=new JsonResult();
        List<Map<String, Object>> goodsAllByBrand = brandService.findGoodsAllByBrand(id, memory, color, size);
        jsonResult.setCode("1");
        jsonResult.setMsg("检索成功");
        jsonResult.setData(goodsAllByBrand);
        return jsonResult.getValues();
    }




}
